package jifenbao.com.jifenbao;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TabHost;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jifenbao.com.entity.MyEntity;

/**
 * Created by longteng on 2016-5-24.
 */
public class ShopTicket extends AppCompatActivity {
    private TabHost tabHost;
    private ListView shopticketView;
    final List<MyEntity> myentityList = new ArrayList<>();
    final List<Map<String,String>> shopticket = new ArrayList<>();
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_ticket_listview);

        shopticketView = (ListView)findViewById(R.id.shopticket);
        //List<Map<String,String>> shopticket = new ArrayList<>();
        Map<String,String> shopticketmap1 = new HashMap<>();
        shopticketmap1.put("ticket_value","5");
        shopticketmap1.put("ticket_name","新店沙拉套餐优惠券");
        shopticketmap1.put("ticket_full","满10元可用");
        shopticket.add(shopticketmap1);

        Map<String,String> shopticketmap2 = new HashMap<>();
        shopticketmap2.put("ticket_value","10");
        shopticketmap2.put("ticket_name","健身餐周套餐优惠券");
        shopticketmap2.put("ticket_full","满30元可用");
        shopticket.add(shopticketmap2);

        Map<String,String> shopticketmap3 = new HashMap<>();
        shopticketmap3.put("ticket_value","5");
        shopticketmap3.put("ticket_name","新店沙拉水果优惠券");
        shopticketmap3.put("ticket_full","满10元可用");
        shopticket.add(shopticketmap3);

        Map<String,String> shopticketmap4 = new HashMap<>();
        shopticketmap4.put("ticket_value","5");
        shopticketmap4.put("ticket_name","减脂套餐优惠券");
        shopticketmap4.put("ticket_full","满10元可用");
        shopticket.add(shopticketmap4);

        SimpleAdapter myAdapter = new SimpleAdapter(this,shopticket,R.layout.activity_shop_ticket_valid,
                new String[]{"ticket_value","ticket_name","ticket_full"},
                new int[]{R.id.ticket_value,R.id.ticket_name,R.id.ticket_full});
        shopticketView.setAdapter(myAdapter);

//            myentityList.add(new MyEntity (10,"haha",10));

//        shopticketView.setAdapter(new MyAdapter(this,myentityList));

        FindTabs();
        ticketListener();

    }

    public void FindTabs(){
        tabHost = (TabHost)findViewById(android.R.id.tabhost);
        tabHost.setup();
        tabHost.addTab(tabHost.newTabSpec("valid").setContent(R.id.shopticket).setIndicator("可用"));
        tabHost.addTab(tabHost.newTabSpec("invalid").setContent(R.id.RightLayout).setIndicator("失效"));
    }

    public void ticketListener(){
        shopticketView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent saveintent = new Intent(ShopTicket.this,CouponDetail.class);
                Map<String,String> TicketClick = shopticket.get(position);
                saveintent.putExtra("value",TicketClick.get("ticket_value"));
                saveintent.putExtra("name",TicketClick.get("ticket_name"));
                saveintent.putExtra("full",TicketClick.get("ticket_full"));
                startActivity(saveintent);
            }
        });
    }
}
